{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "87443003",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu_1801\":\"ZiQi\",\n",
    "    \"stu_1802\":\"XiaoFeng\",\n",
    "    \"stu_1803\":\"Liuyu\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "490e6805",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_1801\n",
      "stu_1802\n",
      "stu_1803\n"
     ]
    }
   ],
   "source": [
    "for i in info:\n",
    "    print(i)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f87afb7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_1801 ZiQi\n",
      "stu_1802 XiaoFeng\n",
      "stu_1803 Liuyu\n"
     ]
    }
   ],
   "source": [
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4a481dc9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践1:stu1801 中取出数字，作为新的字典key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "510b37fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'_1801': 'ZiQi', '_1802': 'XiaoFeng', '_1803': 'Liuyu'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "11d5f774",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践2: value 我也想变，所有字母大写\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "78a1dd69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'_1801': 'ZIQI', '_1802': 'XIAOFENG', '_1803': 'LIUYU'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1e06b1a4",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-13-2976dd26227f>, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-13-2976dd26227f>\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m    new_info[int k[3:]] = v.upper()\u001b[0m\n\u001b[0m                 ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 实践3:让new_info key由‘1801’=>1801\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[int k[3:]] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e17a3570",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'_1801': 'ZIQI', '_1802': 'XIAOFENG', '_1803': 'LIUYU'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bee99e08",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
